package com.bdqn.ch06.SZ;


import com.bdqn.ch06.SZ.Service.UserService;
import com.bdqn.ch06.SZ.entity.User;
import com.bdqn.ch06.SZ.mapper.UserDao;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import static org.junit.Assert.*;

public class SpeakTalkTestSZ {

    public static void main(String[] args) {

        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("SpeakTalkSZ.xml");

//        SpeakTalk speakTalk= (SpeakTalk)applicationContext.getBean("speakTalk");
//        speakTalk.print();
        /**
         * 20:37:13.238 [main] DEBUG org.springframework.context.support.ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@5d22bbb7
         * 20:37:13.407 [main] DEBUG org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loaded 1 bean definitions from class path resource [SpeakTalkSZ.xml]
         * 20:37:13.449 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'speakTalk'
         * 诸葛亮： 我从未见过如此厚颜无耻之人 ！
         * 路飞：我要成为海贼王的男人 ！
         */

        // 实战 2

//        User userLu = applicationContext.getBean("speakTalkPLu", User.class);
//        System.out.println(userLu.getUsername()+userLu.getEvaluate());
//
//        User userZhu = applicationContext.getBean("speakTalkPZhu", User.class);
//        System.out.println(userZhu.getUsername()+userZhu.getEvaluate());
        /**
         * 20:53:52.978 [main] DEBUG org.springframework.context.support.ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@5d22bbb7
         * 20:53:53.169 [main] DEBUG org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loaded 3 bean definitions from class path resource [SpeakTalkSZ.xml]
         * 20:53:53.228 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'speakTalk'
         * 20:53:53.259 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'speakTalkPZhu'
         * 20:53:53.291 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'speakTalkPLu'
         * 路飞：我是要成为海贼王的男人
         * 诸葛亮：我从未见过如此厚颜无耻之人
         */

//        UserService user = (UserService) applicationContext.getBean("userP");
//        User user1 = new User();
//        user1.setUsername("1");
//        user.save(user1);

        /**
         * 21:32:43.212 [main] DEBUG org.springframework.context.support.ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@5d22bbb7
         * 21:32:43.401 [main] DEBUG org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loaded 5 bean definitions from class path resource [SpeakTalkSZ.xml]
         * 21:32:43.457 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'speakTalk'
         * 21:32:43.492 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'speakTalkPZhu'
         * 21:32:43.524 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'speakTalkPLu'
         * 21:32:43.530 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'userDao'
         * 21:32:43.530 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'userP'
         * 保存用户到数据库
         */

//        ch06 实战4 使用注解实现依赖注入
//        UserService userService = (UserService) applicationContext.getBean("userService");
//        User user = new User();
//        user.setUsername("哈哈哈");
//        userService.save(user);

        /**
         * ch06 使用注解实现依赖注入
         * 09:27:03.976 [main] DEBUG org.springframework.context.support.ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@606d8acf
         * 09:27:04.507 [main] DEBUG org.springframework.context.annotation.ClassPathBeanDefinitionScanner - Identified candidate component class: file [D:\Frame\frames\mavenss\target\classes\com\bdqn\ch06\SZ\mapper\impl\UserDaoImpl.class]
         * 09:27:04.558 [main] DEBUG org.springframework.context.annotation.ClassPathBeanDefinitionScanner - Identified candidate component class: file [D:\Frame\frames\mavenss\target\classes\com\bdqn\ch06\SZ\Service\impl\UserServiceImpl.class]
         * 09:27:04.574 [main] DEBUG org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loaded 10 bean definitions from class path resource [SpeakTalkSZ.xml]
         * 09:27:04.613 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
         * 09:27:04.676 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.event.internalEventListenerProcessor'
         * 09:27:04.678 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.event.internalEventListenerFactory'
         * 09:27:04.680 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
         * 09:27:04.682 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor'
         * 09:27:04.700 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'speakTalk'
         * 09:27:04.743 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'speakTalkPZhu'
         * 09:27:04.783 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'speakTalkPLu'
         * 09:27:04.785 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'UserDao'
         * 09:27:04.787 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'userService'
         * 保存用户到数据库
         */

        // ch06 实战5 标注注解的装配功能
        UserService user = (UserService) applicationContext.getBean("userService");
        User user1 = new User();
        user1.setUsername("1");
        user.save(user1);

        /**
         * 09:43:47.315 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'userService'
         * 09:43:47.401 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'com.bdqn.ch06.SZ.UserServiceLoggers#0'
         * 2024-07-22 09:43:47 [ INFO] 调用 com.bdqn.ch06.SZ.Service.impl.UserServiceImpl@1613674b 的save 方法。方法入参： [User{id=0, username='1', ok=null, sex= , birthday=null, salary=null, intTechs=null, strTechs=null}] com.bdqn.ch06.SZ.UserServiceLoggers.before(UserServiceLoggers.java:47)
         * 保存用户到数据库
         * 2024-07-22 09:43:47 [ INFO] 调用 com.bdqn.ch06.SZ.Service.impl.UserServiceImpl@1613674b 的save 方法。方法入参： null com.bdqn.ch06.SZ.UserServiceLoggers.afterReturning(UserServiceLoggers.java:58)
         */

    }

}